<template>
  <el-select v-model="selectEle" value-key="code" filterable placeholder="请选择" @change="changeValue($event)" clearable style="width:100%">
    <el-option
      v-for="item in supplierList"
      :key="item.code"
      :label="item.name"
      :value="item"
    />
  </el-select>
</template>
<script>
  import request from '@/utils/request'
  export default {
    data() {
      return {
        // 选中的对象，这里由于要支持返回对象，所以model中的值是一个对象
        selectEle: {
          code: '',
          name: '',
        },
        supplierList: [],
        callbackMethod: '',
        shipmentName: '',
        warehouseCode: '',
      }
    },
    created() {
      this.findList();
    },
    methods: {
      findList() {
        return request({
          url: '/wms/supplier/search',
          method: 'get',
        }).then(response => {
          this.supplierList = response.data
        }).catch((error) => {
          console.log(error)
        })
      },
      setSelectValue(value) {
        this.$nextTick(()=>{
          this.supplierList.forEach(i => {
            if (i.code == value || i.name == value) {
              this.selectEle = i;
            }
          })
        })
      },
      changeValue(e) {
        this.$emit('setsupplierCode', e)
      }
    }
  }
</script>
